package com.lie.prepare.multi_thread.queue;


/**
 * Created by lie on 2018/4/9.
 * 涂果酱
 */
public class Jammer implements Runnable {

    private ToastQueue butteredQueue, finishedQueue;

    public Jammer(ToastQueue butteredQueue, ToastQueue finishedQueue) {
        this.butteredQueue = butteredQueue;
        this.finishedQueue = finishedQueue;
    }

    public void run() {
        try {
            while (!Thread.interrupted()) {
                Toast toast = butteredQueue.take();
                toast.jam();
                System.out.println(toast);
                finishedQueue.put(toast);

            }
        }catch (InterruptedException e) {
            System.out.println("Jammer InterruptedException");

        }
        System.out.println("Jammer off");
    }
}
